package hash;

import java.util.*;

public class Test {
    public static void main(String[] args) {
        TreeSet<Integer> treeSet = new TreeSet<>();
        treeSet.add(10);
        treeSet.add(100);
        treeSet.add(85);
        treeSet.add(32);

        System.out.println(treeSet.contains(100));

        Iterator<Integer> it = treeSet.iterator();
        while(it.hasNext()){
            System.out.print(it.next() + " ");
        }
        System.out.println();

        System.out.println("======演示删除======");

        treeSet.remove(100);

        it = treeSet.iterator();
        while(it.hasNext()){
            System.out.print(it.next() + " ");
        }
        System.out.println();

        System.out.println(treeSet.size());

        System.out.println(treeSet.isEmpty());

        Integer[] arr = (Integer[])treeSet.toArray(new Integer[0]);

        for (int x: arr) {
            System.out.print(x+"  ");
        }
    }
    public static void main4(String[] args) {
        HashMap<String,Integer> map = new HashMap<>();
        map.put("abcd",123);
        map.put("hello",64);
        map.put("world",256);
        map.put("error",1024);
        map.put("null",1024);

        Set<Map.Entry<String,Integer>> set = map.entrySet();

        for(Map.Entry<String,Integer> x: set) {
            x.setValue(10256);
        }

        System.out.println("======================");
        System.out.println("检测将每个键值对的 value 设置为 10256是否成功");

        for(Map.Entry<String,Integer> x: set) {
            System.out.println("key: " + x.getKey() + "   val: " + x.getValue());
        }
    }
    public static void main3(String[] args) {
        HashMap<String,Integer> map = new HashMap<>();
        map.put("abcd",123);
        map.put("hello",64);
        map.put("world",256);
        map.put("error",1024);
        map.put("null",1024);

        Set<String> set = map.keySet();

        System.out.println(set);

        Collection<Integer> c = map.values();

        System.out.println(c);
    }
    public static void main2(String[] args) {
        HashMap<String,Integer> map = new HashMap<>();
        map.put("abcd",123);
        map.put("hello",64);
        map.put("world",256);
        map.put("error",1024);
        map.put("null",1024);

        System.out.println(map.entrySet());

        map.remove("abcd");

        System.out.println("======================");

        System.out.println(map.entrySet());
    }
    public static void main1(String[] args) {
        HashMap<String,Integer> map = new HashMap<>();
        map.put("abcd",123);
        map.put("hello",64);
        map.put("world",256);
        map.put("error",1024);

        System.out.println("size: " + map.size());

        System.out.println("hello: " + map.get("hello"));

        System.out.println(map.containsKey("ab"));

        System.out.println(map.containsValue(256));
    }
}
